using System;
using JetBrains.Annotations;

namespace Kaleida.ServiceMonitor.Model.Runtime
{
    public class RequestSuccessResult : RequestResult
    {
        private readonly TimeSpan requestDuration;
        private readonly string summary;

        public RequestSuccessResult(IOperation operation, DateTime sentOn, TimeSpan requestDuration, [NotNull] string summary)
            : base(operation, sentOn)
        {
            if (summary == null) throw new ArgumentNullException("summary");
            this.requestDuration = requestDuration;
            this.summary = summary;
        }

        public TimeSpan RequestDuration
        {
            get { return requestDuration; }
        }

        private int RequestDurationMilliseconds
        {
            get { return (int)requestDuration.TotalMilliseconds; }
        }
        
        public override string ToListItemText()
        {
            var responseText = summary == "" ? "" : ". " + summary;
            return string.Format("{0:dd-MMM-yyyy HH:mm:ss.fff}: {1} ms ({2}){3}", SentOn, RequestDurationMilliseconds, Operation.Description, responseText);
        }

        public override string ToClipboardItemText()
        {
            return string.Format("{0:dd-MMM-yyyy HH:mm:ss.fff}\t{1}\t{2}\t{3}", SentOn, RequestDurationMilliseconds, Operation.Description, summary);
        }
    }
}